<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="../jquery/jquery-1.11.3.js"></script>
<link rel="stylesheet" href="../CSS/CompanyAllJob.css">
	<style >
	 #In-table{
	 	border: 1;
		width:500px;
		height:50px;
		margin-top:20px;
	 }
	</style>
<title>工作岗位</title>
</head>
<body>
	<div id="Header">
		<div class="Header-Logo">
			<a href="http://www.baidu.com">
				<img src="../images/yy.png" alt="YY招聘网">
			</a>
		</div>
		<div class="Header-Logo-Right">
			<ul>
				<li>
					<a href="CompanyAllJob.html">招聘情况</a>
				</li><li>
					<a id="getCompany" href="alertJob.html" >修改岗位</a>
				</li>
			</ul>
		</div>
	</div>
	<div id="Content">
		<div class="Content-Background"></div>
		<div class="Content-Background-Content">
			
			<div id="Main-Div" ></div>
				
			
			<div class="First-Next">
					<input type="button" value="首页" id="firstPage" />
					<input type="button" value="上一页" id="prePage">
					<input type="button" value="下一页" id="nextPage">
					<input type="button" value="尾页" id="lastPage"><br/>
					总共<span id="pageNum"></span>页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					当前第<span id="pageNow"></span>页 
			</div>
			</div>
	</div>

	
	<script >
	/*function getCookie(name){
			var arr =document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));

		　　		if(arr !=null) return unescape(arr[2]);
		　　		return null;
		}
		alert(getCookie("baobao"));
		var companyId = getCookie("baobao");
		console.log("companyId+"+companyId);
		alert(typeof(companyId));
		var jobcompany =companyId>>0;
		alert(jobcompany);*/
		var jobcompany=sessionStorage.comLogin;
		var jobJson;
		var Num;//获取的总数
		var totalpage;
		var currpage=1;
		var mark;//记录最后一页的数据个数
		alert(""+jobcompany);
		$.ajax({
			type : "GET",
			url: "../Resume/getCompanyJob.action?CompanyLoginName="+jobcompany,
			dataType : "json",
			success:function(data){
				jobJson = data;
				
				Num=data.num;
				alert(Num);
				
				$.makeDiv();
				
			},
			error:function(jqXHR){
				alert("发生错误： "+jqXHR.status);
			}
		});
		
		$.makeDiv=function(){
			var fPage = document.getElementById("firstPage");//首页
			var pPage = document.getElementById("prePage");//前一页
			var nPage = document.getElementById("nextPage");//后一页
			var lPage = document.getElementById("lastPage");//尾页
			var numPage = document.getElementById("pageNum");//总的页数
			var nowPage = document.getElementById("pageNow");//当前页
			var mainDiv=document.getElementById("Main-Div");
			if(Num%4==0){
				totalpage=Num/4;
				numPage.innerHTML=totalpage;
				mark=4;
			}
			else{
				totalpage=Num/4+1;
				totalpage=Math.floor(totalpage);
				numPage.innerHTML=totalpage;
				mark=Num%4;
				//mark=Math.floor(mark);
			}
			lPage.onclick=function(){
				currpage=totalpage;
				mainDiv.innerHTML="";
				nowPage.innerHTML=currpage;
				for(i=0;i<mark;i++){
			
					var mjobid=jobJson.data[(currpage*4)-4+i].jobId;
					var mjobname=jobJson.data[(currpage*4)-4+i].jobName;
					var mjobcompany=jobJson.data[(currpage*4)-4+i].jobCompany;
					var mjobnum=jobJson.data[(currpage*4)-4+i].jobNum;
					var mjobhave=jobJson.data[(currpage*4)-4+i].jobHave;
					
					var lDiv = document.createElement("div");
					var rDiv = document.createElement("div");
					var zDiv = document.createElement("div");
					
					lDiv.className = "leftDiv";
					rDiv.className = "rightDiv";
					zDiv.className = "zongDiv";
					
					var jobName = document.createElement("p");
					var jobNum = document.createElement("p");
					var jobHave = document.createElement("p");
					
					var pA=document.createElement("a");
					pA.className="AA";
					pA.innerHTML="查看详情";
					pA.setAttribute("href","javascript:void(0)");
					pA.setAttribute("id",mjobid+","+mjobname);
					pA.onclick=function(){
						postJobId("Jid",this.id);
					}
					
					jobName.innerHTML = "岗位名称: "+mjobname;
					jobNum.innerHTML = "总人数: "+mjobnum;
					jobHave.innerHTML = "已有人数: "+mjobhave;
					
					
					lDiv.appendChild(jobName);
					lDiv.appendChild(jobNum);
					lDiv.appendChild(jobHave);
					rDiv.appendChild(pA);
					
					mainDiv.appendChild(zDiv);
					zDiv.appendChild(lDiv);
					zDiv.appendChild(rDiv);
					//mainDiv.appendChild(rDiv);
				}
			}
			fPage.onclick=function(){
				if(Num<4){
					lPage.onclick();
				}
				else{
					currpage=1;
					mainDiv.innerHTML="";
					nowPage.innerHTML=1;
				for(var i=0;i<4;i++){
				
					//var mainDiv=document.getElementById("Main-Div");
					var mjobid=jobJson.data[i].jobId;
					var mjobname=jobJson.data[i].jobName;
					var mjobcompany=jobJson.data[i].jobCompany;
					var mjobnum=jobJson.data[i].jobNum;
					var mjobhave=jobJson.data[i].jobHave;
					
					var lDiv = document.createElement("div");
					var rDiv = document.createElement("div");
					var zDiv = document.createElement("div");
					
					lDiv.className = "leftDiv";
					rDiv.className = "rightDiv";
					zDiv.className = "zongDiv";
					
					var jobName = document.createElement("p");
					var jobNum = document.createElement("p");
					var jobHave = document.createElement("p");
					
					var pA=document.createElement("a");
					pA.className="AA";
					pA.innerHTML="查看详情";
					pA.setAttribute("href","javascript:void(0)");
					pA.setAttribute("id",mjobid+","+mjobname);
					pA.onclick=function(){
						postJobId("Jid",this.id);
					}
					
					jobName.innerHTML = "岗位名称: "+mjobname;
					jobNum.innerHTML = "总人数: "+mjobnum;
					jobHave.innerHTML = "已有人数: "+mjobhave;
					
					
					lDiv.appendChild(jobName);
					lDiv.appendChild(jobNum);
					lDiv.appendChild(jobHave);
					rDiv.appendChild(pA);
					
					mainDiv.appendChild(zDiv);
					zDiv.appendChild(lDiv);
					zDiv.appendChild(rDiv);
					//mainDiv.appendChild(rDiv);
				}
				}
			}
		
			pPage.onclick=function(){
				if(currpage==1){
					alert("已经是首页了");
				}
				else{
					currpage-=1;
					
					mainDiv.innerHTML="";
					nowPage.innerHTML=currpage;
					for(var i=0;i<4;i++){
						var mjobid=jobJson.data[(currpage*4)-4+i].jobId;
						var mjobname=jobJson.data[(currpage*4)-4+i].jobName;
						var mjobcompany=jobJson.data[(currpage*4)-4+i].jobCompany;
						var mjobnum=jobJson.data[(currpage*4)-4+i].jobNum;
						var mjobhave=jobJson.data[(currpage*4)-4+i].jobHave;
						
						var lDiv = document.createElement("div");
						var rDiv = document.createElement("div");
						var zDiv = document.createElement("div");
						
						lDiv.className = "leftDiv";
						rDiv.className = "rightDiv";
						zDiv.className = "zongDiv";
						
						var jobName = document.createElement("p");
						var jobNum = document.createElement("p");
						var jobHave = document.createElement("p");
						
						var pA=document.createElement("a");
						pA.className="AA";
						pA.innerHTML="查看详情";
						pA.setAttribute("href","javascript:void(0)");
						pA.setAttribute("id",mjobid+","+mjobname);
						pA.onclick=function(){
							postJobId("Jid",this.id);
						}
						
						jobName.innerHTML = "岗位名称: "+mjobname;
						jobNum.innerHTML = "总人数: "+mjobnum;
						jobHave.innerHTML = "已有人数: "+mjobhave;
						
						
						lDiv.appendChild(jobName);
						lDiv.appendChild(jobNum);
						lDiv.appendChild(jobHave);
						rDiv.appendChild(pA);
						
						mainDiv.appendChild(zDiv);
						zDiv.appendChild(lDiv);
						zDiv.appendChild(rDiv);
						//mainDiv.appendChild(rDiv);
					}
				}
			}
			nPage.onclick=function(){			
				if(currpage==totalpage){
					alert("已经是最后一页了");
				}
				else{
					currpage=currpage+1;
					if(currpage==totalpage){
						
						lPage.onclick();
					}
					else{
						nowPage.innerHTML=currpage;
						mainDiv.innerHTML="";
						for(var i=0;i<4;i++){
							
							var mjobid=jobJson.data[(currpage*4)-4+i].jobId;
							var mjobname=jobJson.data[(currpage*4)-4+i].jobName;
							var mjobcompany=jobJson.data[(currpage*4)-4+i].jobCompany;
							var mjobnum=jobJson.data[(currpage*4)-4+i].jobNum;
							var mjobhave=jobJson.data[(currpage*4)-4+i].jobHave;
							
							var lDiv = document.createElement("div");
							var rDiv = document.createElement("div");
							var zDiv = document.createElement("div");
							
							lDiv.className = "leftDiv";
							rDiv.className = "rightDiv";
							zDiv.className = "zongDiv";
							
							var jobName = document.createElement("p");
							var jobNum = document.createElement("p");
							var jobHave = document.createElement("p");
							
							var pA=document.createElement("a");
							pA.className="AA";
							pA.innerHTML="查看详情";
							
							pA.setAttribute("href","javascript:void(0)");
							pA.setAttribute("id",mjobid+","+mjobname);
							pA.onclick=function(){
								postJobId("Jid",this.id);
							}
							
							jobName.innerHTML = "岗位名称: "+mjobname;
							jobNum.innerHTML = "总人数: "+mjobnum;
							jobHave.innerHTML = "已有人数: "+mjobhave;
							
							
							lDiv.appendChild(jobName);
							lDiv.appendChild(jobNum);
							lDiv.appendChild(jobHave);
							rDiv.appendChild(pA);
							
							mainDiv.appendChild(zDiv);
							zDiv.appendChild(lDiv);
							zDiv.appendChild(rDiv);
							//mainDiv.appendChild(rDiv);
						}
					}
				}
			}
			if(currpage==1){
				fPage.onclick();
			}
			
			
		
	}
	
	
	function postJobId(name,value2){
	//	alert("name+"+name);
	//	alert("value+"+value2);
		var mark2 = value2.split(",");
		var jId = mark2[0];
		var jName = mark2[1];
		var sendJson={
			"id":jId,
			"name":jName
		};
		var Days = 1; //此 cookie 将被保存 1 天
		var exp　= new Date();
		console.log("exp.getTime()+"+exp.getTime());
		exp.setTime(exp.getTime() +Days*24*60*60*1000);
		
	
		sessionStorage.setItem("jId",JSON.stringify(sendJson));
			//document.cookie = name +"="+ escape (value2) + ";expires=" + exp.toGMTString();
		
		location.href = "JobUser.html";
		
	}
		/*function getCookie(){
			var cookie = {};						//初始化最后要返回的对象
			alert(typeof(cookie));
			var all = document.cookie;
			
			if(all === ""){
				return cookie;
			}
			var list = all.split(","); 				//分离出名/值对
			for(var i=0;i<list.length;i++){
				var cookie2 = list[i];
				var p = cookie2.indexOf("=");		//查找第一个"="符号
				var name = cookie2.substring(0,p);   //获取cookie名字
				var value = cookie2.substring(p+1);	//获取cookie对应的值
				value = unescape(value);			//解码
				cookie["name"] = value;
				//alert()
			}
			return cookie;
		}*/
		
	</script>
</body>
</html>